package com.ibeeking.found.file.rest.controller.v1;

import com.ibeeking.found.common.config.prop.FileOssProp;
import com.ibeeking.found.file.rest.service.IOssFileService;
import com.ibeeking.found.file.service.common.query.DownloadQuery;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.file.oss.config.OssService;
import com.ibeeking.nematos.file.oss.dto.OssPolicyDto;
import com.ibeeking.nematos.log.annotation.Log;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author ibeeking
 * 粉丝标签关系
 */
@RestController
@RequestMapping("/b/file/oss/v1")
public class OssFileController {

    @Resource
    private FileOssProp fileOssProp;

    @Resource
    private IOssFileService ossFileServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "获取上传OSS签名")
    @GetMapping(value = "/policy")
    public OssPolicyDto policy() {
        OssPolicyDto policy = OssService.policy();
        policy.setPreviewHost(fileOssProp.getHost());
        return policy;
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "文件下载")
    @PostMapping(value = "/download")
    public void download(@RequestBody @Validated DownloadQuery query, HttpServletResponse response) {
        ossFileServiceImpl.download(query.getKey(), response);
    }
}
